<template>
	<view class="register_content">
		<view class="logo">
			<view class="logo-1">
				{{title}}
			</view>
			<view class="logo-2">
				提交修改后请使用新的密码登录
			</view>
		</view>
		<view class="login_form">
			<view class="login_form_row">
				<view class="iconfont iconshoujihao">

				</view>
				<input class="login_form_rowinput" type="text" v-model="form.loginname" maxlength="11"
					placeholder="请输入手机号" />
			</view>
			<view class="login_form_row">
				<view class="iconfont iconyanzhengma2">

				</view>
				<input class="login_form_rowinput" v-model="form.code" type="text" placeholder="请输入验证码" />
				<view class="y" @click="getCodes" v-if="!showCode">获取验证码</view>
				<view class="y" v-if="showCode" style="color: #666;">{{num}}s后再次获取</view>
			</view>
			<view class="login_form_row">
				<view class="iconfont iconmima1">

				</view>
				<input class="login_form_rowinput" type="password" :password="true" v-model="form.password"
					maxlength="11" placeholder="请输入密码" />
			</view>
			<view class="login_form_row">
				<view class="iconfont iconzaicimima1">

				</view>
				<input class="login_form_rowinput" type="password" :password="true" v-model="passwords" maxlength="11"
					placeholder="请再次输入密码" />
			</view>
			<view class="" style="font-size: 24upx;color: #999;padding: 30upx 0;padding-top: 15upx;">
				密码长度为8到20位，必须包含字母、数字、特殊符号中的俩种，字母区分大小写
			</view>
		</view>
		<view class="bnts" @click="register()">
			提交
		</view>

	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		data: function() {
			return {
				form: {
					loginname: '',
					password: '',
					code: '',
				},
				showCode: false,
				passwords: '',
				num: 60,
				title: '找回密码'
			}
		},
		onLoad(options) {
			if (options.id) {
				this.title = '修改密码'
			}
		},
		methods: {
			...mapMutations(['getData']),
			getCodes() {
				if (this.form.loginname == '') {
					uni.showToast({
						title: '请输入手机号码',
						icon: "none",
						duration: 3000
					})
					return false
				}
				const that = this;
				const obj = {
					url: 'app/user/sendSMS',
					data: {
						phone: this.form.loginname,
						type: '2'
					},
					success() {
						that.showCode = true
						var sI = setInterval(function() {
							that.num -= 1
							if (that.num == 0) {
								that.showCode = false
								that.num = 60
								clearInterval(sI)
							}
						}, 1000)
					},
					fail(res) {},
					complete(res) {
						console.log(res)
					}
				}
				this.getData(obj)
			},
			register() {
				switch ('') {
					case this.form.loginname:
						uni.showToast({
							title: '请输入手机号码',
							icon: "none",
							duration: 3000
						})
						return false;
					case this.form.code:
						uni.showToast({
							title: '请输入验证码',
							icon: "none",
							duration: 3000
						})
						return false;
					case this.form.password:
						uni.showToast({
							title: '请输入密码',
							icon: "none",
							duration: 3000
						})
						return false;
				}
				if (this.form.password != this.passwords) {
					uni.showToast({
						title: '两次密码不一致',
						icon: "none",
						duration: 3000
					})
					return false;
				}
				let that = this
				const obj = {
					url: 'app/user/forgetPwd',
					data: {
						...this.form
					},
					success() {
						uni.navigateBack()
					},
					fail(res) {
						uni.showToast({
							title: res.msg,
							duration: 3000,
							icon: 'none'
						});
					},
					complete(res) {
						console.log(res)
					}
				}
				this.getData(obj)
			},
		},
	}
</script>

<style lang="scss" scoped>
	.logo {
		padding-top: 100upx;
		margin: 0 60upx;

		.logo-1 {
			font-size: 48upx;
			font-weight: 500;
		}

		.logo-2 {
			font-size: 28upx;
			color: #666;
		}

	}

	.login_form {
		background-color: #f7f7f7;
		margin: 0 60upx;
		padding: 0 30upx;
		border-radius: 24upx;
		margin-top: 100upx;

		.login_form_row {
			display: flex;
			align-items: center;
			height: 100upx;
			border-bottom: 2upx solid #ebebeb;

			.iconfont {
				font-size: 42upx;
				padding-right: 25upx;
				color: #000;
			}

			.login_form_rowinput {
				flex: 1;
				height: 100%;
				font-size: 30upx;
			}

			.y {
				width: 180upx;
				height: 50upx;
				line-height: 50upx;
				border-left: 2upx solid #ebebeb;
				color: #3478f6;
				font-size: 26upx;
				text-align: center;
			}
		}
	}

	.bnts {
		height: 90upx;
		line-height: 90upx;
		margin: 0 50upx;
		background-color: #3478f6;
		border-radius: 45upx;
		text-align: center;
		color: #fff;
		margin-top: 100upx;
	}

	.mask {
		width: 100%;
		font-size: 26upx;
		color: #646464;
		margin-top: 30upx;
		padding: 10upx 0;
		display: flex;
		align-items: center;
		justify-content: center;

		.iconfont {
			padding-right: 4upx;
			font-size: 36upx;
		}

	}

	.register_content {
		flex: 1;
		justify-content: center;
		align-items: center;
		background: #fff;
		height: 100%;
		overflow: auto;
	}
</style>